home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- CPixelWorldPane.c
-
- The PixelWorldPane Class
-
- The CPixelWorldPane class is a subclass of CPanorama that uses a
- CPixelWorld object to display a color or grayscale image that is
- kept offscreen. An offscreen color graphics device (GDevice) and an
- offscreen color graphics port (CGrafPort) are used to maintain this
- offscreen world. This implementation supports 1,2,4 and 8 bit pixel
- depths. Pixel depths of 16 and 32 bits are not currently supported.
-
- This implementation does not depend upon any 32-Bit QuickDraw features.
- Future versions of the CPixelWorld class will provide support for pixel
- depths of 16 and 32 bits, and for GWorlds under 32-Bit QuickDraw.
-
- SUPERCLASS = CPanorama
-
- This implementation is based in part on material copyrighted by
- Symantec Corporation and Apple Computer, Inc.
-
- Copyright © 1992 Vincent R. Vann, Jr. All rights reserved.
-
- Version 1.2 Changes:
- [
- - changed class definition to make the superclass CPanorama
- instead of CBitMapPane as in the original implementation.
- - modified the SetPixelWorld method so that the bounds, position,
- and origin of the PixelWorldPane are changed to reflect the
- new PixelWorld's coordinates. This method also refreshes the
- pane so that the image of the new PixelWorld will be drawn.
- ]
-
- ******************************************************************************/
-
- #include "CPixelWorldPane.h"
- #include "Exceptions.h"
- #include "Global.h"
- #include "LongQD.h"
-
-
- /**** C O N S T R U C T I O N / D E S T R U C T I O N M E T H O D S ****/
-
-
- /******************************************************************************
- IPixelWorldPane
-
- Initialize a PixelWorldPane object
- ******************************************************************************/
-
- void CPixelWorldPane::IPixelWorldPane(
- CView *anEnclosure,
- CBureaucrat *aSupervisor,
- short aWidth,
- short aHeight,
- short aHEncl,
- short aVEncl,
- SizingOption aHSizing,
- SizingOption aVSizing,
- LongRect *aBounds,
- CPixelWorld *aPixelWorld)
- {
- itsPixelWorld = NULL;
-
- CPanorama::IPanorama(
- anEnclosure, aSupervisor, aWidth, aHeight,
- aHEncl, aVEncl, aHSizing, aVSizing);
-
- bounds = *aBounds;
-
- position.h = bounds.left;
- position.v = bounds.top;
-
- itsPixelWorld = aPixelWorld;
-
- IPixelWorldPaneX();
- }
-
-
- void CPixelWorldPane::IPixelWorldPaneX()
- {
- if (itsPixelWorld == NULL) /* Create a default pixel world */
- {
- Rect r;
- LongRect lRect;
- GDHandle gdev;
- PixMapHandle pmap;
- short depth;
-
- if (gSystem.hasColorQD) /* World has color */
- {
- r = (**GrayRgn).rgnBBox; /* Use rect that covers all screens */
-
- gdev = GetMaxDevice( &r); /* Get device with max pixel depth */
- pmap = (**gdev).gdPMap; /* Get the device's PixMap */
- depth = (**pmap).pixelSize; /* Get the device's pixel depth */
-
- if (depth > 8) /* Pixel depth must be <= 8 */
- depth = 8;
- }
- else /* World is black and white */
- {
- depth = 1; /* Use pixel depth of 1 */
- }
-
- lRect = bounds;
- LongToQDRect( &lRect, &r);
-
- itsPixelWorld = new( CPixelWorld);
- itsPixelWorld->IPixelWorld( depth, &r, NULL, NULL, 0);
- }
-
- autoRefresh = FALSE;
- }
-
-
- /******************************************************************************
- Dispose {OVERRIDE}
-
- Dispose of a PixelWorldPane
- ******************************************************************************/
-
- void CPixelWorldPane::Dispose()
- {
- if (itsPixelWorld != NULL)
- {
- itsPixelWorld->Dispose();
- itsPixelWorld = NULL;
- }
-
- inherited::Dispose();
- }
-
-
- /******************************************************************************
- GetPixelWorld
-
- Return a reference to the PixelWorld associated with a PixelWorldPane
- ******************************************************************************/
-
- CPixelWorld* CPixelWorldPane::GetPixelWorld()
- {
- return( itsPixelWorld);
- }
-
-
- /******************************************************************************
- SetPixelWorld
-
- Specify the PixelWorld associated with a PixelWorldPane
- ******************************************************************************/
-
- void CPixelWorldPane::SetPixelWorld(
- CPixelWorld* aPixelWorld)
- {
- if (aPixelWorld != itsPixelWorld)
- {
- LongRect lRect;
- LongPt lPt;
-
- itsPixelWorld = aPixelWorld;
-
- if (aPixelWorld != NULL)
- aPixelWorld->GetBounds( &lRect);
- else
- SetLongRect( &lRect, 0, 0, 0, 0);
-
- lPt.h = lRect.left;
- lPt.v = lRect.top;
-
- SetFrameOrigin( lRect.left, lRect.top);
- SetBounds( &lRect);
- SetPosition( &lPt);
-
- Refresh();
- }
- }
-
-
- /******************************************************************************
- Draw {OVERRIDE}
-
- Draw a PixelWorldPane
- ******************************************************************************/
-
- void CPixelWorldPane::Draw(
- Rect *area)
- {
- LongRect lBounds, lArea;
- Rect bounds;
-
- if (itsPixelWorld != NULL)
- {
- itsPixelWorld->GetBounds( &lBounds);
- LongToQDRect( &lBounds, &bounds);
-
- SectRect(area, &bounds, area);
- QDToFrameR( area, &lArea);
-
- itsPixelWorld->CopyFrom( &lArea, &lArea, NULL);
- }
- else
- EraseRect( area);
- }
-
-